package com.wn.advice;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * @author yellow Docter
 * @date 2022 -07-07
 * @desc
 * 切面类 : 通知 + 连接点
 */
@Aspect
@Component
public class MyAspect {

//    @Before(value = "execution(* com.wn.service.UserServiceImpl.save())")
//    public void before(){
//        System.out.println("MyAspect.before" + "前置通知....");
//    }
//
//    @After(value = "execution(* com.wn.service.*.*())")
//    public void after(){
//        System.out.println("MyAspect.after" + "最终通知....");
//    }

    @Around(value = "execution(* com.wn.service.*.*(..))")
    public Object around(ProceedingJoinPoint joinPoint){

        Object[] args = joinPoint.getArgs();
        Object result= null;

        Object arg = args[1];
        String s = arg.toString();
        Double money = Double.valueOf(s);

        try {
            result = joinPoint.proceed(args);
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        System.out.println("money = " + money);
        if (money > 100){
            result = "不会勤俭节约...";
        }
        return result;
    }

}
